<template>
	<div class="dynamicManager w944">
		<alert ref="alert"></alert>
		<deleteAlert ref="deleteAlert"></deleteAlert>
		
		<div class="label_top">
			<p><i class="line"></i>动态管理</p>
		</div>
		<div class="label_table">
			<div class="el-tabs-report">
				<commonMethods ref="commonMethods" style="display: inline-block;"></commonMethods>
				<!--<el-date-picker v-model="screenDate" type="datetimerange" :picker-options="pickerOptions" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right" @change="getTableList"></el-date-picker>-->
				<a class="listTwo" @click="importDaoChu" v-if="dynamicManager.dtgl_export">导出数据</a>
				<div class="msearch">
					<input placeholder="请输入学员关键词……" v-model="search"/>
					<a @click="getPageSearch"><img src="../../assets/qudaoImg/search.png"/></a>
				</div> 
			</div>
			<el-table ref="multipleTable" :data="tableData" border @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55"></el-table-column>
				<el-table-column label="学员名称">
					<template slot-scope="scope">
						<span><img src="../../assets/qudaoImg/anonymous.png" v-if="scope.row.cryptonym==1">{{scope.row.nickname}}<i class="cancellation" v-if="scope.row.userStatus!=1">（已注销）</i></span>
					</template>
				</el-table-column>
				<el-table-column label="动态内容">
					<template slot-scope="scope">
						<el-button @click="handleSeen(scope.row)">查看</el-button>
					</template>
				</el-table-column>
				<el-table-column prop="createTime" label="发布时间"></el-table-column>
				<el-table-column label="操作" width="100">
					<template slot-scope="scope">
						<el-button @click="handleDelete(scope.row)" v-if="dynamicManager.dtgl_del" class="red">删除</el-button>
					</template>
				</el-table-column>
			</el-table> 
			<div class="fenyeMargin">
				<el-button @click="toggleSelection(tableData)" class="allSelect">全选</el-button>
				<el-button @click="handleDeleteAll" class="allDelete" v-if="dynamicManager.dtgl_delAll">批量删除</el-button>
				<div class="pag_block">
					<el-pagination @current-change="handleCurrentChange" :current-page="currentpage" :page-size="pagesize" layout="prev, pager, next" :total="total"></el-pagination>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import alert from '../../components/Alert.vue';
	import deleteAlert from '../../components/deleteAlert.vue';
	import commonMethods from '../../components/common.vue';
	export default {
		data() {
			return {
				dynamicManager:'',
				search:'',
				tableData:[],
				multipleSelection: [],
		        pagesize: 15,
		        currentpage: 1,
		        total: 1,
		        deleteType:'delete',
//				screenDate:'',
//				pickerOptions:{}
			}
		},
		methods: {
			getTableList(){
				this.pickerOptions = this.$refs.commonMethods.pickerOptions;
				console.log(22222,this.$refs.commonMethods.screenDate);
				this.$ajax({
					url: this.$root.jifuUrl + "/mns/qzDtHt/selectQzDtList",
					headers:{'ContentType': 'application/json; charset=utf-8'},
					method: 'POST',
					data: {
						page:this.currentpage,
						num:this.pagesize,
						rootcompanyid:1,
						fuzzyFields:this.search,
						startCreateTime:this.$refs.commonMethods.screenDate[0],
						endCreateTime:this.$refs.commonMethods.screenDate[1]
					},
					success: res => {
						console.log(res);
						if(res.data.code == 200) {
							this.tableData = res.data.data.list;
							this.total=res.data.data.pageParam.items;
						}
					}
				});
			},
			handleDelete(row){
				this.transitionRow = row;
				this.$rootFunction().rootDelete();
			},
			handleDeleteAll(){
				this.$rootFunction().rootDeleteAll();
			},
			deleteSubmit() {
				if(this.deleteType == 'delete'){
					let arr = [];
					arr.push(this.transitionRow.id);
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/qzDtHt/deleteQzDtList",
						headers:{'ContentType': 'application/json; charset=utf-8'},
						method: 'POST',
						data:arr,
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}else{ 
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/qzDtHt/deleteQzDtList",
						headers:{'ContentType': 'application/json; charset=utf-8'},
						method: 'POST',
						data:this.multipleSelection,
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}
			},
			handleSeen(row){
				this.$router.push({
					name:'dynamicContent',
					params: {
						countId:row.id
					}
				})
			},
			toggleSelection(rows) {
				if(rows) {
					rows.forEach(row => {
						this.$refs.multipleTable.toggleRowSelection(row, !this.allSelect)
					})
					this.allSelect = !this.allSelect;
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = [];
				val.forEach(row => {
					this.multipleSelection.push(row.id);
				})
			},
			handleCurrentChange(value) {
				this.currentpage = value;
				this.getTableList();
			},
			getPageSearch(){
				this.currentpage=1;
				this.getTableList();
			},
			importDaoChu(){
				
			}
		},
		components: {
			alert,
			deleteAlert,
			commonMethods
		},
		mounted: function() {
			this.getTableList();
			this.dynamicManager = this.$root.huasan.dynamicManager;
		}
	}
</script>